{% macro input(name, title, value="", required=true, length=190) -%}
    <div class="layui-form-item">
        <label for="{{name}}" class="layui-form-label"> {% if required %}<span class="x-red">*</span>{% endif %}{{title}}: </label>
        <div class="layui-input-inline">
            <input {% if length != 190 %}style="width:{{length}}px"{% endif %} type="text" id="{{name}}" name="{{name}}" 
                required="" {% if required %}lay-verify="{{name}}"{% endif %} autocomplete="off" class="layui-input" value="{{ value }}" placeholder="请输入{{title}}" />
        </div>
        <div class="layui-form-mid layui-word-aux"> </div>
    </div>
{% endmacro input -%}

{% macro number(name, title, value="") -%}
    <div class="layui-form-item">
        <label for="{{name}}" class="layui-form-label"> <span class="x-red">*</span> {{title}}: </label>
        <div class="layui-input-inline">
            <input style="width:95px" type="text" id="{{name}}" name="{{name}}" 
                required="" {% if required %}lay-verify="{{name}}"{% endif %} autocomplete="off" class="layui-input" value="{{ value }}" placeholder="请输入{{title}}" />
        </div>
        <div class="layui-form-mid layui-word-aux"> </div>
    </div>
{% endmacro number -%}

{% macro remark(value="", required=false) -%}
    <div class="layui-form-item">
        <label for="remark" class="layui-form-label"> {% if required %}<span class="x-red">*</span>{% endif %} 备注: </label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" placeholder="请输入备注" id="remark" name="remark" {% if required %}lay-verify="{{name}}"{% endif %}>{{value}}</textarea>
        </div>
        <div class="layui-form-mid layui-word-aux"> </div>
    </div>
{% endmacro remark -%}

{% macro textarea(name, title, value="", required=false) -%}
    <div class="layui-form-item">
        <label for="{{name}}" class="layui-form-label"> {% if required %}<span class="x-red">*</span>{% endif %} {{title}}: </label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" placeholder="请输入{{title}}" id="{{name}}" name="{{name}}" {% if required %}lay-verify="{{name}}"{% endif %}>{{value}}</textarea>
        </div>
        <div class="layui-form-mid layui-word-aux"> </div>
    </div>
{% endmacro textarea -%}

{% macro password(name, title, required=true, note="") -%}
    <div class="layui-form-item">
        <label for="{{name}}" class="layui-form-label"> <span class="x-red">*</span>{{title}}: </label>
        <div class="layui-input-inline">
            <input type="password" id="{{name}}" name="{{name}}" required="" {% if required %}lay-verify="{{name}}"{% endif %} autocomplete="off" class="layui-input" placeholder="请输入{{title}}" />
        </div>
        <div class="layui-form-mid layui-word-aux"> {{note}} </div>
    </div>
{% endmacro password -%}

{% macro state(value) -%}
    <div class="layui-form-item">
        <label for="state" class="layui-form-label"> <span class="x-red">*</span>状态: </label>
        <div class="layui-input-inline">
            <select name="state" lay-verify="required">
                <option value="0" {% if value == 0 %}selected="selected"{% endif %}>禁用</option>
                <option value="1" {% if value == 1 %}selected="selected"{% endif %}>启用</option>
            </select>
        </div>
        <div class="layui-form-mid layui-word-aux"> </div>
    </div>
{% endmacro state -%}

{% macro yes_no(name, title, value="", note="") -%}
    <div class="layui-form-item">
        <label for="{{name}}" class="layui-form-label"> <span class="x-red">*</span>{{title}}: </label>
        <div class="layui-input-inline">
            <select name="{{name}}" lay-verify="required">
                <option value="0" {% if value == 0 %}selected="selected"{% endif %}>否</option>
                <option value="1" {% if value == 1 %}selected="selected"{% endif %}>是</option>
            </select>
        </div>
        <div class="layui-form-mid layui-word-aux"> {{note}} </div>
    </div>
{% endmacro yes_no -%}

{% macro list(name, title, data, value="", note="") -%}
    <div class="layui-form-item">
        <label for="{{name}}" class="layui-form-label"> <span class="x-red">*</span>{{title}}: </label>
        <div class="layui-input-inline">
            <select name="{{name}}" lay-verify="required">
                {% for key, val in data %}
                {% set val_id = "" ~ value -%}
                <option value="{{key}}" {% if val_id == key %}selected="selected"{% endif %}>{{val}}</option>
                {% endfor -%}
            </select>
        </div>
        <div class="layui-form-mid layui-word-aux"> {{note}} </div>
    </div>
{% endmacro list -%}

{% macro seq(value) -%}
    <div class="layui-form-item">
        <label for="seq" class="layui-form-label"> <span class="x-red">*</span>排序: </label>
        <div class="layui-input-inline">
            <input style="width: 95px;" type="text" id="seq" name="seq" required="true" lay-verify="required" 
                autocomplete="off" class="layui-input" placeholder="请输入排序" value="{{ value }}" />
        </div>
        <div class="layui-form-mid layui-word-aux"> </div>
    </div>
{% endmacro seq -%}

{% macro file(name, title, value="") -%}
    <div class="layui-form-item">
        <label for="{{name}}_el" class="layui-form-label"> <span class="x-red">*</span> {{title}}: </label>
        <div class="layui-input-inline">
            <button type="button" class="layui-btn" id="{{name}}_el">
                <i class="layui-icon">&#xe67c;</i>{{title}}
            </button>
            <input  type="hidden" id="{{name}}" name="{{name}}" class="layui-input" value="{{value}}" />
        </div>
        <div class="layui-form-mid layui-word-aux"> </div>
    </div>
    <script>
    layui.use(['upload', 'jquery'], function(){
        var upload = layui.upload, $ = layui.jquery;
        var uploadInst = upload.render({ //执行实例
            elem: '#{{name}}_el', //绑定元素
            url: '/index/upload', //上传接口
            done: function(res){ //上传完毕回调
                if (res.code == 0) { 
                    $("#{{name}}").val(res.path);
                }
            },
            error: function() { }
        });
    });
    </script>
{% endmacro file -%}

{% macro checkboxes(name, title, data, value="") -%}
<div class="layui-form-item">
    <label for="{{name}}" class="layui-form-label"> <span class="x-red">*</span>{{title}}: </label>
    <div class="layui-input-inline" style="width: 380px;">
        {% set check_ids = "," ~ value ~ "," %}
        {% for key, val in data -%}
        {% set check_id = "," ~ key ~ "," %}
        <input type="checkbox" class="check_{{name}}" name="check_{{name}}_{{key}}" value="{{key}}" title="{{val}}" {% if check_ids is containing(check_id) %}checked="checked"{% endif %} />
        {% endfor -%}
    </div>
    <input type="hidden" value="{{value}}" name="{{name}}" id="{{name}}" />
    <div class="layui-form-mid layui-word-aux"> </div>
</div>
<script>
layui.use(['jquery', 'form'], function() { 
    var $ = layui.jquery, form = layui.form;
    form.on('checkbox', function(obj) { 
        var ids = new Array();
        $(".check_{{name}}").each(function() { 
            var that = $(this);
            var checked = that.is(":checked");
            if (checked) { 
                ids.push(that.val());
            }
        });
        $("#{{name}}").val(ids.toString());
    });
});
</script>
{% endmacro checkboxes -%}
